/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package multi.agent.simulation;

import java.util.ArrayList;

/**
 *
 * @author Fernando
 */
public class BestRoadReply {
    
    public String RequestID;
    public String ReplierName;  
    public double Weight;
    public ArrayList<String> Road;
    public Boolean IsValid;
    
    public BestRoadReply() {
        Road = new ArrayList<>();
    }
    
    public String toMessageString(){
        String msg = RequestID + ";" + ReplierName + ";" + Weight + ";" + IsValid + ";";
        for (int i = 0; i < Road.size(); i++){
            msg += Road.get(i) + ",";
        }
        return msg;
    }
    
    public static BestRoadReply FromMessageString(String messageString) {
        BestRoadReply brr = new BestRoadReply();
        String[] split = messageString.split(";");
        brr.RequestID = split[0];
        brr.ReplierName = split[1];
        brr.Weight = Double.parseDouble(split[2]);
        brr.IsValid = Boolean.parseBoolean(split[3]);
        brr.Road = new ArrayList<>();
        if (split[4] != ""){
            String[] roadSplit = split[4].split(",");
            for (int i = 0; i < roadSplit.length; i++){
                brr.Road.add(roadSplit[i]);
            }
        }
        return brr;
    }
}